package com.example.miniappssm.controller;

import com.example.miniappssm.bean.Goods;
import com.example.miniappssm.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @RequestMapping("/showAllGoods")
    public List<List<Goods>> showAllGoods() {
        return goodsService.selectAllGoods();
    }

    @RequestMapping("/showGoods")
    public Goods showGoods(@RequestParam("goodsId") Integer goodsId) {
        return goodsService.selectGodsByGoodsId(goodsId);
    }

    @PostMapping("/updateGoods")
    public void updateGoods(Goods goods) {
        goodsService.updateGoods(goods);
    }

    @PostMapping("/addGoods")
    public void insertGoods(Goods goods) {
        goodsService.insertGoods(goods);
    }

    @RequestMapping("/removeGoods")
    public void removeGoods(@RequestParam("goodsId") Integer goodsId) {
        goodsService.removeGoodsByGoodsId(goodsId);
    }
}
